package com.basker.pisces.domain.validation.validator;

import com.basker.pisces.domain.validation.IDependOnValidation;
import com.basker.pisces.domain.validation.meta.Validation;
import com.basker.pisces.spring.SpringApplicationContext;

public class ValidatorFactory {
    public static ICommandValidator createEntityCommandValidator(Validation validation) {
        ICommandValidator validator = SpringApplicationContext.getInstance().getBean(validation.getValidatorBeanName(),
                ICommandValidator.class);

        if (validator instanceof IDependOnValidation) {
            ((IDependOnValidation) validator).setValidation(validation);
        }

        return validator;
    }
}
